class SendMailController < ApplicationController
  def create_order

    #发送邮件
    
    #调用purchase的数据和数据关系，填写到邮件的内容里
    purchase = Purchase.findPidSendMesg(params[:purId])
    begin
      ids= params[:id][1..params[:id].length-2].split(',');
      for id in ids
        sender = Vendor.find(id).linkman_email
        #可以更改此处的邮箱地址，发给不同的用户
        email = OrderMailer.deliver_confirm(sender,purchase)
        #发送短信
        #          phone = User.find(id).linkman_mobile
        #          logger.info phone
        #          beginTime = purchase.begin_time.to_s[0,16]
        #          endTime =  purchase.end_time.to_s[0,16]
        #          cgNumber = purchase.order_number
        #          params = {}
        #          params["cdkey"] = '0SDK-EMY-0130-LFQUK'
        #          params["password"] = '131253'
        #          params["phone"] = phone
        #          params["message"] = '浩海网络竞价平台提醒您：采购单号为：'+cgNumber+'竞价开始时间：'+beginTime+'竞价结束时间：'+endTime
        #          uri = URI.parse("http://sdkhttp.eucp.b2m.cn/sdkproxy/sendsms.action")
        #          res = Net::HTTP.post_form(uri, params)
      end
      info = 'success'
    rescue Exception=>e
      info = e.to_s
    end
    result = "{success:true,info:\"#{info}\"}"
    render :text=>result, :layout=>false
  end

end